package com.study;

/*
 *
 *  长、宽、半径、形状
 *  计算周长、计算面积。
 *
 * */

public class Shape {
    double width;
    double height;
    double radius;
    private String shape;

    public Shape(double[] arr) {
        if (arr.length == 2) {
            this.width = arr[0];
            this.height = arr[1];
            this.shape = "长方形";
        } else {
            this.radius = arr[0];
            this.shape = "圆形";
        }
    }
    public String getShape(){
        return this.shape;
    }

    public double perimeter() {
        return Math.round(
            (this.shape == "长方形" ? (this.width + this.height) * 2 : 2 * 3.14 * this.radius)
        );
    }
    public double area() {
        return Math.round(
            (this.shape == "长方形" ? this.width * this.height : 3.14 * this.radius * this.radius)
        );
    }

    public void printData(double[] arr){
        for(int i = 0; i < arr.length; i++){
            System.out.println("当前是第"+ i +"个值：" + arr[i]);
        }

//        int i = 0;
//        while (i < arr.length){
//            System.out.println("当前是第"+ i +"个值：" + arr[i]);
//            i++;
//        }

//        int i = 0;
//        do{
//            System.out.println("当前是第"+ i +"个值：" + arr[i]);
//            i++;
//        }while(i < arr.length);
    }


}
